﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PTUDW_CNTN2010_F_CDT.Models;
using PTUDW_CNTN2010_F_CDT.Filters;

namespace PTUDW_CNTN2010_F_CDT.Controllers
{
    [LanguageFilter]
    public class HomeController : Controller
    {
        private EcommerceDBContext db = new EcommerceDBContext();

        public ActionResult Index()
        {
            var products = db.Products.Include(p => p.Category);
            return View(products.ToList());
        }

        public ActionResult Search(string productName)
        {
            ViewBag.Category = new SelectList(db.Categories, "CategoryId", "CategoryName");
            var products = db.Products.Where(p => p.ProductName == productName);

            return View(products.ToList());
        }

        public ActionResult AdvancedSearch(int categoryID, int minVal, int maxVal)
        {
            ViewBag.Category = new SelectList(db.Categories, "CategoryId", "CategoryName");

            var products = db.Products.Where(p => p.CategoryId == categoryID && p.Price >= minVal && p.Price <= maxVal);
            return View(products.ToList());
        }
    }
}
